//
//  LYBadgeView.swift
//  1010
//
//  Created by 米明 on 15/8/7.
//  Copyright (c) 2015年 米明. All rights reserved.
//

import UIKit

class LYBadgeView: UIView {

    class func showMessage(score:Int) {
        
        //label
        let message = UILabel(frame: CGRect(x: 0, y: 0, width: SCREEN_SIZE.width, height: 100))
        message.center = CGPoint(x: SCREEN_SIZE.width/2.0, y: SCREEN_SIZE.height/2.0)
        message.font = UIFont(name: FONT_STANK, size: 58)
        message.textAlignment=NSTextAlignment.center
        message.shadowColor=LYColor.white
        message.shadowOffset=CGSize(width: 2, height: 2)
        
        //color
        var color:UIColor!
        
        print("消除的行数: \(score)")
        
        //text
        var text:String!
        
        if  score <= 1 {
            color = customColor(red: 60, green: 160, blue: 229, alpha: 1)
            text = "Good!"
        }
        else if score > 1 && score <= 3 {
            color = customColor(red: 65, green: 173, blue: 57, alpha: 1)
            text = "Great!"

        }
        else if score > 3 && score <= 5 {
            color = customColor(red: 225, green: 143, blue: 21, alpha: 1)
            text = "Cool!"
        }
        else if score > 5  {
            color = customColor(red: 250, green: 203, blue: 13, alpha: 1)
            text = "Perfect!"
        }
        
        message.textColor=color
        message.text=text
        
        //动画
        message.transform=CGAffineTransform(scaleX: 0.5, y: 0.5)
        
        UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.86, initialSpringVelocity: 2.5, options: [], animations: {
            message.transform=CGAffineTransform(scaleX: 1, y: 1)
        }) { (finished) -> Void in
            UIView.animate(withDuration: 0.2, delay: 0.5, options: [], animations: {
                message.transform=CGAffineTransform(scaleX: 0.7, y: 0.7)
                message.alpha=0
            }, completion: { (finished) -> Void in
                message.removeFromSuperview()
            })
        }
        
        let window = UIApplication.shared.keyWindow
        
        window?.addSubview(message)
        
    }
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
